<template>
  <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="570px">
    <el-form ref="form" :model="form"  :inline="true" size="small" label-width="100px" :rules="rules" >
      <el-form-item label="用户名" prop="userName" >
        <el-input v-model="form.userName"  />
      </el-form-item>
      <el-form-item label="密码" >
        <el-input v-model="form.passWord"  />
      </el-form-item>
      <el-form-item label="性别" >
        <el-select v-model="form.sexId" placeholder="请选择">
          <el-option
            v-for="item in sexOptions"
            :key="item.value"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出生日期"  >
        <el-date-picker
          v-model="form.birthday"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          placeholder="选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否有效" >
        <el-switch
          v-model="form.isValid"
          active-color="#409EFF"
          inactive-color="#F56C6C"
          active-value="Y"
          inactive-value="N">
        </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="crud.cancelCU">取消</el-button>
      <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import {crud, form} from '@/components/f-crud/f-crud'

  const defaultForm = {id: null, userId: null, userName: '', passWord: '', sexId: 'M', birthday: '1991-01-01', isValid: 'Y'}
  export default {
    mixins: [crud(), form(defaultForm)],
    data () {
      return {
        sexOptions: [{
          value: 'M',
          name: '男'
        }, {
          value: 'W',
          name: '女'
        }],
        rules: {
          userName: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur'}
          ]
        }
      }
    }
  }
</script>
<style scoped>
</style>
